package com.mhs.sync;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class RequestSignalSync extends Service{
	private static final String TAG = "ServiceRequestSignalSync";
	private Timer timer;
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	@Override
	public void onCreate() {
		Toast.makeText(this, "Service Request Signal Sync Created", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onCreate");
		timer = new Timer();
	}
	
	@Override
	public void onDestroy() {
		Toast.makeText(this, "Service Request Signal Sync Stopped", Toast.LENGTH_LONG).show();
		Log.d(TAG, "onDestroy");
	}
	
	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		long delay = 2000; // delay for 5 sec.
		long period = 10000; // repeat every sec.
		timer.scheduleAtFixedRate(new TimerTask() {
			@Override
			public void run() {
				Intent intent = new Intent();
				intent.setAction("com.mhs.sync.Sync");
				intent.setClass(getBaseContext(), com.mhs.sync.Sync.class);
				startService(intent);
				//TimerMethod();
			}
		}, delay, period);
		
	}

//	private void TimerMethod() {
//		this.runOnUiThread(Timer_Tick);
//	}
//
//	private Runnable Timer_Tick = new Runnable() {
//		public void run() {
//
//		//This method runs in the same thread as the UI.    	       
//
//		//Do something to the UI thread here
//
//		}
//	};
}
